<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>回复</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no"/>
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="stylesheet" href="/static/admin/static/component/pear/css/pear.css" />
    <link href="/static/public/libs/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/public/libs/perfree-comment/perfree-comment.css?v=#(version)" rel="stylesheet">
    <style>
        .perfree-comment{
            width: 100%;
        }
        .comment-emjoi-panel-show{
            flex-direction: row;
        }
        .comment-submit-box{
            display: none;
        }
        .comment-emjoi-panel-show::-webkit-scrollbar{
            width: 6px;
            height: 6px;
        }
        .comment-emjoi-panel-show::-webkit-scrollbar-corner{
            background: #f6f6f6;
        }
        .comment-emjoi-panel-show::-webkit-scrollbar-thumb{
            background: #E6E6E6;
            border-radius: 2px;
        }
        .comment-emjoi-panel-show::-webkit-scrollbar-track{
            background: white;
            border-radius: 2px;
        }
    </style>
</head>
<body>
<form class="layui-form" lay-filter="addForm">
    <div class="mainBox">
        <div class="main-container">
            <div class="layui-input-inline"  style="display: none;">
                <select lay-verify="" type="hidden"></select>
            </div>

            <div class="perfree-comment" data-article-id="#(comment.articleId)" data-show-comment-list="false" data-pid="#(comment.id)" data-top-pid="#(comment.topPid == -1 ? comment.id : comment.topPid)"></div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="button" lay-submit lay-filter="addForm" class="pear-btn pear-btn-primary pear-btn-sm">
                <i class="fa fa-check" aria-hidden="true"></i> 确定
            </button>
            <button type="button" class="pear-btn pear-btn-sm p-cancel-btn">
                <i class="fa fa-close" aria-hidden="true"></i> 取消
            </button>
        </div>
    </div>
</form>
<script src="/static/public/libs/jquery/jquery-3.5.1.min.js"></script>
<script src="/static/public/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="/static/admin/static/component/pear/pear.js"></script>
<script src="/static/public/libs/perfree-comment/perfree-comment.js?v=#(version)"></script>
<script>
    let form, element, layer;
    layui.use(['layer', 'form', 'element'], function () {
        form = layui.form;
        element = layui.element;
        layer = layui.layer;
        form.verify({});
        form.on('submit(addForm)', function (data) {
            let articleId = $('.comment-box').attr('data-article-id');
            let pid = $('.comment-box').attr('data-pid');
            let topPid = $('.comment-box').attr('data-top-pid');
            let content = $('.comment-editor').html();
            $.ajax({
                type: "POST",
                url: "/admin/comment/reply",
                contentType: "application/json",
                data: JSON.stringify({articleId, pid, topPid, content}),
                success: function (data) {
                    if (data.code === 200) {
                        parent.queryTable();
                        parent.parent.toast.success({message: '回复成功',position: 'topCenter'});
                        const index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        parent.parent.toast.error({message: data.msg,position: 'topCenter'});
                    }
                },
                error: function (data) {
                    parent.parent.toast.error({message: "回复失败",position: 'topCenter'});
                }
            });
            return false;
        });
    });

    // 取消
    $(".p-cancel-btn").click(function () {
        const index = parent.layer.getFrameIndex(window.name);
        parent.layer.close(index);
    });
</script>
</body>
</html>